Skip to content

Add alias schema option #5184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2017
Merged

Add alias schema option #5184

merged 6 commits into from
May 14, 2017

Conversation

rkt2spc
Copy link
Contributor

@rkt2spc rkt2spc commented Apr 20, 2017

Summary
Supporting alias is a great feature for an ORM. Currently, we already have virtual getter/setter, I just incorporate them into a schema option for usability

var schema = new Schema({
  foo: { type: String, alias: 'bar' } // Create virtual getter/setter
});

Test plan

var Schema = mongoose.Schema;
var TestSchema = new Schema({
  foo: { type: String, alias: 'Faa' },
  bar: {
    baz: { type: String, alias: 'Baa' },
    kar: { type: String, alias: 'Kaa' }
  }
});
var Test = mongoose.model('Test', TestSchema);
var test = new Test({
  foo: 'a',
  bar: {
    baz: 'b',
    kar: 'c',
  }
});

assert.equal(test.foo, test.Faa);
assert.equal(test.bar.baz, test.Baa);
test.Kaa = 'd';
assert.equal(test.bar.kar, test.Kaa);

@rkt2spc
Copy link
Contributor Author

rkt2spc commented Apr 20, 2017

Plan to incorporate alias into query and constructor

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a very neat solution to a feature we've wanted for a while. Will merge with 4.10.0 (ETA April 30)

@rkt2spc
Copy link
Contributor Author

rkt2spc commented Apr 23, 2017

Lol, checks fail on "model indexes auto creation can be disabled". Hmm...

@rkt2spc rkt2spc closed this Apr 23, 2017
@rkt2spc rkt2spc reopened this Apr 23, 2017
@rkt2spc
Copy link
Contributor Author

rkt2spc commented Apr 23, 2017

Close and reopen the PR to trigger a rebuild now reporting no error

@vkarpov15 vkarpov15 mentioned this pull request Apr 30, 2017
@vkarpov15 vkarpov15 changed the base branch from master to 4.10 May 14, 2017 02:51
@vkarpov15 vkarpov15 merged commit bafa678 into Automattic:4.10 May 14, 2017
vkarpov15 added a commit that referenced this pull request May 26, 2017
@rkt2spc rkt2spc mentioned this pull request Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants